/*
@STI LICENSE
(C) 2006-2008 Universit�t Innsbruck.

This file is part of myOntology.

myOntologyis free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

myOntologyis distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with myOntology.  If not, see <http://www.gnu.org/licenses/>.

@STI LICENSE */
/**
 * 
 */
package org.myontology.controller.pages;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.myontology.controller.AttributeHolder;
import org.myontology.controller.AttributeLevel;
import org.myontology.controller.PageProvider;
import org.myontology.controller.ValueHandler;

/**
 * @author <a href="michael.hackl@sti2.at">Michael Hackl</a>
 * Project: Myontology - www.myontology.org
 * STI
 *
 */
public class BasicPage implements PageProvider {

	private Map<String,String> contentMap = new ConcurrentHashMap<String,String>();
	public static final ValueHandler<Map<String,String>> CONTENT = new ValueHandler<Map<String,String>>(AttributeLevel.REQUEST,BasicPage.class);
	
	public BasicPage() {
		
	}
	
	public static void setContent(AttributeHolder attributes,String value) {
		set(attributes,"content",value);
	}
	public static void set(AttributeHolder attributes,String key,String value) {
		getMap(attributes).put(key, value);
	}
	
	private static Map<String,String> getMap(AttributeHolder attributes) {
		Map<String,String> map = CONTENT.getValue(attributes);
		if (map==null) {
			map = new HashMap<String, String>();
			CONTENT.setValue(attributes, map);
		}
		return map;
	}
	
	public BasicPage(String key,String value) {
		contentMap.put(key, value);
	}
	
	/* (non-Javadoc)
	 * @see org.myontology.controller.PageProvider#getForward()
	 */

	public String getForward() {
		return "/index.jsp";
	}

	/* (non-Javadoc)
	 * @see org.myontology.controller.PageProvider#getPage(java.lang.String)
	 */

	public String getPage(String key, AttributeHolder attributes) {
		String page = getMap(attributes).get(key);
		if (page==null)
			page=contentMap.get(key);
		return page;
	}

	/* (non-Javadoc)
	 * @see org.myontology.controller.PageProvider#getRedirect()
	 */

	public String getRedirect(AttributeHolder attributes) {
		return null;
	}

}
